
import Loading from './scenes/loading';
import Game from './scenes/game';
import Award from './scenes/award';
import injectStore from 'components/injectStore';

@injectStore
export default class GameApp {

  isRoot = true;

  constructor({store}) {

    const { width, height } = window.CFG.view;

    this.app = new PIXI.Application({
      width: width,
      height: height,
      backgroundColor: 0xffffff,
    });

    store.app = this;

    this.enterScene('loading');
  }

  enterScene = (sceneType) => {

    // 清空stage
    if (this.app.stage.children.length) {
      this.app.stage.removeChildren(0, this.app.stage.children.length);
    }

    let scene = null;


    switch (sceneType) {
      case 'loading': {
        scene = new Loading({parent: this});
        break;
      }
      case 'game': {
        scene = new Game({parent: this});
        break;
      }
      case 'award': {
        scene = new Award({parent: this});
        break;
      }
    }

    this.scene = scene;

    this.app.stage.addChild(scene.container);

  }

};
